package com.cc.main.cmd;

import com.cc.main.Const;
import com.cc.main.ICommonCmd;
import com.cc.main.problems.bean.ProblemBean;
import com.cc.main.util.CcExceeption;
import com.cc.main.util.MyUtils;

/**
 * select选择问题命令
 * @author TR
 *
 */
public class SelectCmd implements ICommonCmd{
	
	public static int id = 0;
	
	public void execute(Object action) throws CcExceeption {
		//打印指令说明
		String problems = "";
		for(int key:Const.pblMap.keySet()) {
			problems += key + ":" + Const.getCmdBean(key).keyCmdDescrips + "  ";
		}
		System.out.println(problems);
		System.out.println("请选择上述问题分类，输入序号即可。");
		while(true) {
			String input = MyUtils.getInput(Const.MSelectCmd);
			if(input.length() == 0) {
				System.out.println("输入错误，请输入数字序列.");
				continue;
			}
			boolean b = MyUtils.isNumeric(input);
			if(!b) {
				System.out.println("输入错误，请输入数字序列.");
				continue;
			}
			
			int idx = Integer.parseInt(input);
			if(idx < 1 || idx > Const.pblMap.size()) {
				System.out.println("输入错误，请输入范围内的数字序列.");
				continue;
			}
			
			id = idx;
			ProblemBean.getInstance().dftkeyList.clear();
			ProblemBean.getInstance().dftkeyList.addAll(Const.getCmdBean(id).defaultKeyList);
			ProblemBean.getInstance().cls = Const.getCmdBean(id).cls;
			break;
		}
	}
	
	@Override
	public String printCurrentEnv() throws CcExceeption {
		// TODO Auto-generated method stub
		if(id == 0) {
			return Const.MSelectCmd + ":";
		}
		return Const.MSelectCmd + ":" + Const.getCmdBean(id).keyCmdDescrips;
	}
}
